package shoppingAnalysis;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class MyCombiner2 extends Reducer<Text, Text, Text, Text> {
	@Override
	protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
		String[] words = key.toString().split("\t");// 分割日期和商品标号
		int sum = 0;
		for (Text value : values) {
			sum += Integer.parseInt(value.toString());
		}
		// key: 商品日期 ,value: 商品标号 + 某个商品当天所有销量
		// 例如value； <<0001,24>,<0002,25>,<0003,50>>
		context.write(new Text(words[0]), new Text(words[1] + "\t" + String.valueOf(sum)));

	}
}
